<template>
	<view class="goods_list">
		<goodsList :goods="goods"></goodsList>
		<view class="isOver" v-if="flag">--我是有底线的--</view>
	</view>
</template>

<script>
	import goodsList from "../../components/goods-list.vue"
	export default {
		data() {
			return {
				pageindex: 1,
				goods: [],
				flag: false,
			}
		},
		components: {
			goodsList
		},
		methods: {
			async getGoodsList(callBack) {
				const res = await this.$myRequest({
					url: '/api/getgoods?pageindex=' + this.pageindex
				})
				console.log(res)
				this.goods = [...this.goods, ...res.data.message]
				callBack && callBack()
			}
		},
		onLoad() {
			this.getGoodsList()
		},
		onReachBottom() {
			if (this.goods.length < 10 * this.pageindex)
				return this.flag = true
			console.log("触底了")
			this.pageindex++
			this.getGoodsList()
		},
		onPullDownRefresh() {
			console.log("下拉刷新")
			this.pageindex = 1
			this.goods = [],
				this.flag = false,
				setTimeout(() => {
					this.getGoodsList(()=>{
						uni.stopPullDownRefresh()
					})
				}, 1000)
		}
	}
</script>

<style lang="scss">
	.goods_list {
		background-color: #eee;
	}

	.isOver {
		width: 100%;
		height: 50px;
		line-height: 50px;
		text-align: center;
		// background-color: #FFFFFF;
		font-size: 28rpx;
	}
</style>
